//
//  SoreViewController.m
//  CaoShi
//
//  Created by aa on 2018/4/20.
//  Copyright © 2018年 杨旭. All rights reserved.
//

#import "YXSoreViewController.h"
#import "YXTitleCell.h"
#import "YXSoreCell.h"
#import "YXSoreTypeViewController.h"
@interface YXSoreViewController ()<UITableViewDataSource,UITableViewDelegate,UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>

@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@end

@implementation YXSoreViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"分类";
    
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);
    self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
    
    // 这个是系统提供的布局类，可以布局一些比较规则的布局。
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    // 设置列的最小间距
    flowLayout.minimumInteritemSpacing = 10;
    // 设置最小行间距
    flowLayout.minimumLineSpacing = 15;
    // 设置布局的内边距
    flowLayout.sectionInset = UIEdgeInsetsMake(15, 20, 0, 20);
    flowLayout.itemSize = CGSizeMake((kScreenWidth-100-60)/2,30 );
    _collectionView.collectionViewLayout = flowLayout;

    self.collectionView.dataSource = self;
    self.collectionView.delegate = self;
    
    [self.tableView registerNib:[UINib nibWithNibName:@"YXTitleCell" bundle:nil] forCellReuseIdentifier:@"YXTitleCell"];
    [self.collectionView registerNib:[UINib nibWithNibName:@"YXSoreCell" bundle:nil] forCellWithReuseIdentifier:@"YXSoreCell"];
    ;}

#pragma mark - UITableView Delegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 4;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return indexPath.row == 0 ? 60 : 44;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    YXTitleCell *cell = [tableView dequeueReusableCellWithIdentifier:@"YXTitleCell" forIndexPath:indexPath];
    cell.titleLab.text = [NSString stringWithFormat:@"%ld",indexPath.row];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
}


#pragma mark - UICollection Delegate
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 3;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    YXSoreCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"YXSoreCell" forIndexPath:indexPath];
    cell.backgroundColor = [UIColor redColor];
    cell.contentLab.text = [NSString stringWithFormat:@"%ld",(long)indexPath.row];
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    YXSoreTypeViewController *vc = [[YXSoreTypeViewController alloc] init];
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
    
}

@end
